package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

import model.Behandling;
import service.Service;

/**
 * 
 * @author Christian
 *
 */

public class PlukMellemvareFrame extends JDialog{
	private JLabel lblMellemvareId, lblAntal, lblPlukAntalMellemvare, lblBehandling, lblBehandlingNavn, lblMellemvareId_3, lblMellemvareAntal;
	private JTextField txfAntal;
	private JButton btnPluk;
	private JButton btnLuk;
	private Behandling b;
	private Controller controller = new Controller();
	
	public PlukMellemvareFrame(Behandling b){
		this.setModal(true);
		this.setSize(300, 220);
		getContentPane().setLayout(null);
		this.b = b;
		lblBehandling = new JLabel("Behandling:");
		lblBehandling.setBounds(10, 11, 80, 29);
		getContentPane().add(lblBehandling);
		
		lblMellemvareId = new JLabel("Mellemvare id:");
		lblMellemvareId.setBounds(10, 40, 109, 22);
		getContentPane().add(lblMellemvareId);
		
		lblAntal = new JLabel("Antal:");
		lblAntal.setBounds(10, 62, 80, 22);
		getContentPane().add(lblAntal);
		
		lblPlukAntalMellemvare = new JLabel("Pluk antal mellemvare:");
		lblPlukAntalMellemvare.setBounds(10, 95, 158, 29);
		getContentPane().add(lblPlukAntalMellemvare);
		
		txfAntal = new JTextField();
		txfAntal.setBounds(150, 95, 66, 29);
		getContentPane().add(txfAntal);
		txfAntal.setColumns(10);
		
		lblBehandlingNavn = new JLabel(b.getNavn());
		lblBehandlingNavn.setBounds(160, 18, 120, 22);
		getContentPane().add(lblBehandlingNavn);
		
		lblMellemvareId_3 = new JLabel(b.getMellemVare().getId() + "");
		lblMellemvareId_3.setBounds(160, 42, 110, 18);
		getContentPane().add(lblMellemvareId_3);
		
		lblMellemvareAntal = new JLabel(b.getMellemVare().getAntalStk() + "");
		lblMellemvareAntal.setBounds(160, 62, 138, 22);
		getContentPane().add(lblMellemvareAntal);
		
		btnPluk = new JButton("Godkend");
		btnPluk.addActionListener(controller);
		btnPluk.setBounds(97, 135, 86, 23);
		getContentPane().add(btnPluk);
		
		btnLuk = new JButton("Luk");
		btnLuk.setBounds(193, 135, 57, 23);
		btnLuk.addActionListener(controller);
		getContentPane().add(btnLuk);
		
	}
	private class Controller implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if(e.getSource() == btnPluk){
				Service.getInstance().plukMellemvare(b.getMellemVare(), Integer.parseInt(txfAntal.getText()));
				dispose();
			}
			else if(e.getSource() == btnLuk){
				dispose();
			}
		}
	}
}
